import { xhlGet } from '../../utils/request'
Page({
  data: {
    vtabs: [ { title: '你好' }, { title: '世界' } ],
    cateSecond: []
  },

  // 请求一级分类数据
  getFirstCateHandler() {
    xhlGet('/jdcatefirst').then(res => this.setData({ vtabs: res }))
  },

  // 请求二级分类数据
  getSecondCateHandler(areaId) {
    xhlGet('/jdcatsecond', { areaId }).then(res => {
      const data = res[0].level1words.filter(item => item.level2words.length)
      this.setData({ cateSecond: data })
    })
  },

  // tab 切换的事件处理函数
  tabChangeHandler(e) {
    const areaId = this.data.vtabs[e.detail.index].paneKey
    this.getSecondCateHandler(areaId)
  },

  onLoad() {
    this.getFirstCateHandler()
    this.getSecondCateHandler('2094')
  }
})